﻿<?php
	include '../inc/conn.php';
	include '../sendmail.php';

	session_start();
	extract($_POST);
	extract($_GET);
	$pagestr = end(explode("/",$_SERVER['PHP_SELF']));
	unset($_POST,$_GET);

	if (isset($act))
	{
		if ($act == 'add' && isset($_SESSION['logname']))
		{
			if (empty($sn) || empty($keyid) || empty($oakey) || empty($lanmac) || empty($wlanmac)){
				echo "<script>alert('数据填写不能为空');window.location='$pagestr';</script>";
				die("数据填写不能为空!");
			}

			if(empty($remark))
				$remark="N/A";

			$db = new mysql();
			$sql="INSERT INTO `dpk_history` (`SN`,`OAKEYID`,`OAKEY`,`HASH_LANMAC`,`HASH_WLANMAC`,`ISMATCH`,`REMARK`) 
				values('${sn}', '${keyid}', '${oakey}', '${lanmac}', '${wlanmac}', '${ismatch}', '${remark}')";
			$db->query($sql);
			echo "<script>alert('数据添加成功!');window.opener.location.reload();window.location.href='$pagestr'</script>";
			$db->close();
		}
		
		if ($act == 'change' && isset($id) && isset($_SESSION['logname']))
		{	
			$db = new mysql();
			
			if(empty($ismatch))
				$ismatch=0;

			if(empty($remark))
				$remark="N/A";

			$table = "dpk_history";
			$condition = "ID=${id}";
			$mod_content="`SN`='${sn}', `OAKEYID`='${keyid}', `OAKEY`='${oakey}', `HASH_LANMAC`='${lanmac}', `HASH_WLANMAC`='${wlanmac}'
						, `ISMATCH`=${ismatch}, `REMARK`='${remark}'";
			$db->update($table, $mod_content, $condition);
			echo "<script>alert('内容修改完成!');window.location.href='$pagestr';</script>";
			$db->close();
		}

		if ($act == 'mail' && isset($id) && isset($_SESSION['logname']))
		{
			$db = new mysql();
			$sql="select * from dpk_history where ID=$id";
			$db->query($sql);
			$num = $db->db_num_rows();
			$row = $db->fetch_assoc();
			
			if($row['ISMATCH']==true)
				$result="<font color='green'>匹配</font>";
			else
				$result="<font color='red'>不匹配</font>";

			$content ="Dear Sirs,<br /><br />&nbsp;&nbsp;当您看到这个邮件时，<b>说明产线在处理OA3 KEY机器时存在市场激活隐患，请制造单位注意处理流程</b>~<br />
					<b>工程处理信息明细如下：</b><br />
					<b>&nbsp;&nbsp;机器序号：</b>${row['SN']}<br />
					<b>&nbsp;&nbsp;DKPID：</b>${row['OAKEYID']}<br />
					<b>&nbsp;&nbsp;KEY：</b>${row['OAKEY']}<br />
					<b>&nbsp;&nbsp;网卡MAC：</b>${row['HASH_LANMAC']}<br />
					<b>&nbsp;&nbsp;无线MAC：</b>${row['HASH_WLANMAC']}<br />
					<b>&nbsp;&nbsp;记录是否匹配：</b>${result}<br />
					<b>&nbsp;&nbsp;备注：</b>${row['REMARK']}<br />
					<b>&nbsp;&nbsp;不匹配原因：</b><font color='red'>换了主板或无线网卡，导致重要KEY信息不符~</font><br />
					<br /><b>处理流程：</b><br />
					  &nbsp;&nbsp;后测PASS有KEY的机器贴上“<b>机器有KEY</b>”标识给维修（机器刷不良进维修系统）->维修确认需要更换主板时需交由->工程处理->完成后维修清理测试记录并可继续进行正常维修";
			if($row['ISMATCH']==false){
				//SendMail("【OA3 KEY记录】存在异常啦~~", $content, "MFG");
				$param = array(
					'aSync'=>'Yes',
					'title'=>'【OA3 KEY记录】存在异常啦~~',
					'msg'=>$content,
					'to'=>'MFG'
				);
				doAsyncMail($param);
			}
			echo "<script>alert('邮件发送完成!');window.location.href='$pagestr';</script>";
			$db->close();
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script>
	$(function(){
		$("#ADDDIV").hide();
		$("#ADDOAKEY").click(function(){
			$("#ADDDIV").toggle();
		});

		$("#addbtn").click(function(){
			if ($("#sn").val() == ""){
				alert("序列号没有填写！");
				return false;
			}

			if ($("#keyid").val() == ""){
				alert("KEYID没有填写！");
				return false;
			}
			
			if ($("#oakey").val() == ""){
				alert("KEY没有填写！");
				return false;
			}

			if ($("#lanmac").val() == ""){
				alert("LAN MAC没有填写！");
				return false;
			}

			if ($("#wlanmac").val() == ""){
				alert("无线MAC没有填写！");
				return false;
			}
		});
	});
</script>
<title>OA3 KEY处理记录</title>
</head>
<body class="background">
<div class="container-fluid white-background pagecontent">
<?
	if(isset($_SESSION['logname'])){
		if ($pagename=="changeitem"){
			echo "<label>操作项次: </label><a id='ADDOAKEY' href='#'> <span class=\"glyphicon glyphicon-plus\"></span>添加</a> | <a id='ADDOAKEY' href='$pagestr'> <span class=\"glyphicon glyphicon-backward\"></span>返回</a>";
		}else{
			echo "<label>操作项次: </label><a id='ADDOAKEY' href='#'> <span class=\"glyphicon glyphicon-plus\"></span>添加</a>";
		}
	}
	echo "<div id='ADDDIV'>\n";
	echo "<form action='$pagestr?act=add' method='post'>\n";
	echo "	<div>\n";
	echo "	添加DPK处理内容:<br />\n";
	echo "		机器序号: <input name='sn' id='sn'><br>\n";
	echo "		KEY  ID: <input name='keyid' id='keyid'><br>\n";
	echo "		OA  KEY: <input name='oakey' id='oakey'><br>\n";
	echo "		网卡MAC: <input name='lanmac' id='lanmac'><br>\n";
	echo "		无线MAC: <input name='wlanmac' id='wlanmac'><br>\n";
	echo "		是否匹配？: <select name='ismatch' id='ismatch'>
					<option value='1'>是</option>
					<option value='0'>否</option>
				</select><br>";
	echo "		备注说明: <input name='remark' id='remark'><br>\n";
	echo "	</div>\n";
	echo "	<div>\n<input class='btn btn-success btn-primary' name='submit' value='提交' type='submit' id='addbtn'>\n<input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
	echo "</form>\n";
	echo "</div>\n";

	// change item page
	if ($pagename=="changeitem"){
		$db = new mysql();
		$sql="select * from dpk_history where ID=$id";
		$db->query($sql);
		$num = $db->db_num_rows();
		$row = $db->fetch_assoc();
		echo "\n<form action='$pagestr?act=change&id=${row['ID']}' method='post'>\n";
		echo "	<div>\n";
		echo "	修改内容:<br />\n";
		echo "		机器序号: <input name='sn' id='sn' value='${row['SN']}'><br>\n";
		echo "		KEY  ID: <input name='keyid' id='keyid' value='${row['OAKEYID']}'><br>\n";
		echo "		OA  KEY: <input name='oakey' id='oakey' value='${row['OAKEY']}'><br>\n";
		echo "		网卡MAC: <input name='lanmac' id='lanmac' value='${row['HASH_LANMAC']}'><br>\n";
		echo "		无线MAC: <input name='wlanmac' id='wlanmac' value='${row['HASH_WLANMAC']}'><br>\n";
		echo "		是否匹配？: <select name='ismatch' id='ismatch'>";
		echo "					<option value='1'>是</option>";
		if($row['ISMATCH']==false)
			echo "				<option value='0' selected='selected'>否</option>";
		else
			echo "				<option value='0'>否</option>";
		echo "				</select><br>";
		echo "		备注说明: <input name='remark' id='remark' value='${row['REMARK']}'><br>\n";
		echo "	</div>\n";
		echo "	<div>\n<input class='btn btn-success btn-primary' name='submit' value='提交' type='submit'>\n";
		echo "  <input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
		echo "</form>\n";
		$db->close();
	}else{
		$db = new mysql();
		$db->query("select * from dpk_history order by add_date desc");
		$num = $db->db_num_rows();
		echo "<table border=0 cellpadding=0 class='table table-striped'>";
		echo "<tr class='success'><th>机器序号</th><th>DPKID</th><th>OA3 KEY</th><th>网卡MAC</th><th>无线MAC</th><th>是否匹配</th><th>处理时间</th><th>操作</th></tr>";
		for($i=0; $i<$num; $i++){
			$row = $db->fetch_assoc();
			echo "<tr>";
			echo "<td>${row['SN']}</td>";
			echo "<td>${row['OAKEYID']}</td>";
			echo "<td>${row['OAKEY']}</td>";
			echo "<td>${row['HASH_LANMAC']}</td>";
			echo "<td>${row['HASH_WLANMAC']}</td>";
			if($row['ISMATCH']==true){
				echo "<td><font color='blue'>匹配</font></td>";
			}else{
				echo "<td><font color='red'>不匹配</font></td>";
			}
			echo "<td>".substr($row['ADD_DATE'],0,10)."</td>";
			if(isset($_SESSION['logname'])){
				echo "<td><a href='$pagestr?pagename=changeitem&id=${row['ID']}'><span class=\"glyphicon glyphicon-edit\"></span></a>";
				if($row['ISMATCH']==false)
					echo " | <a href='$pagestr?act=mail&id=${row['ID']}'><span class=\"glyphicon glyphicon-envelope\"></span></a>";
				echo "</td>";
			}else{
				echo "<td>#</td>";
			}
			echo "</tr>\n";
		}
		echo "</table>";
		$db->close();
	}
?>
</div>
</body>
</html>
